<?php
App::uses('AppController', 'Controller');
/**
 * Sitemaps Controller
 *
 * @property Sitemap $Sitemap
 */
class SitemapsController extends AppController {
  var $name = 'Sitemaps'; 
  var $uses = array('Post', 'Category', 'Product'); 
  var $helpers = array('Time'); 
  var $components = array('RequestHandler'); 

	public function beforeFilter() {
		#parent::beforeFilter();
		#allow not login
		$this->Auth->allow(array('index'));
		$this->loadModel('Product');
		$this->loadModel('Post');
	}

  function index (){     
		#get categories
		$categories = $this->Category->find('all', 
		array('fields' => array('Category.id', 'Category.created_at', 'Category.slug', 'Category.type', 'Category.level'),
														//get products of category
   				'contain' => array('Product' => array('fields' => array('Product.slug', 'Product.id', 'Product.updated_at'),
																								'conditions' => array('Product.status' => Product::active)),
														//get post of category
														'Post' => array('fields' => array('Post.slug', 'Post.id', 'Post.updated_at'),
																						'conditions' => array('Post.status' => Post::publish)),
														'Parent' => array('fields' => array('Parent.id', 'Parent.slug'))
					)));
		$this->set('categories', $categories);
		#Configure::write ('debug', 0); 
  }
}
